import Repayment from "@/types/response/repayment";
import axiosManager from "@/axios/axiosManager";
import ResUtil from "@/utils/resUtil";

let request=axiosManager.caseAxios;



//根据还款id删除还款方法
async function deleteRepaymentById(repaymentId: number) {
    let res=await request.delete('/repayment?repaymentId='+repaymentId);
    return ResUtil.isSuccess(res);
}


//修改还款方案
async function modifyRepaymentPlan(repayment: Repayment) {
    let res=await  request.put('/repayment', repayment);
    return ResUtil.getData<Repayment>(res);
}

//根据机构id获取还款方案列表
async function getRepaymentListByInsId(insId: number) {
    let res=await request.get('/repayments?InsId='+insId);
    return ResUtil.getData<Repayment[]>(res);
}

//根据案件id和还款id获取还款信息
async function getRepaymentInfo( repaymentId: number) {
    let res=await request.get('/repayment?repaymentId='+repaymentId);
    return ResUtil.getData<Repayment>(res);
}

//新增还款方案
async function addRepaymentPlan(repayment: Repayment) {
    let res=await request.post('/repayment', repayment);
    return ResUtil.getData<Repayment>(res);
}
async function getRepaymentInfoByCaseId( caseId: number): Promise<Repayment[]> {
    let res=await request.request({
        method: 'GET',
        url:'/repaymentToCase',
        params: {
            caseId: caseId
        }
    })
    return ResUtil.getData<Repayment[]>(res);
}
async function agreeRepaymentPlan( caseId: number, repaymentId: number) {
    let res=await request.request({
        method: 'put',
        url:'/case/repayment/agree',
        params: {
            caseId: caseId,
            repaymentId: repaymentId
        }
    })
    return ResUtil.getData<Repayment>(res);
}

export {addRepaymentPlan,getRepaymentInfo,getRepaymentListByInsId,modifyRepaymentPlan,deleteRepaymentById,getRepaymentInfoByCaseId,agreeRepaymentPlan}